/*
 * @Author: your name
 * @Date: 2021-12-20 19:51:56
 * @LastEditTime: 2021-12-21 11:20:50
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day10 react\my-app\src\views\index\home\home.js
 */
import React, { Component } from 'react';

// import {gethome} from "../../../api/api"
import {connect} from "react-redux"
import {getHome} from "../../../store/action"
 
class Home extends Component {

    state={
        list:[]
    }

   componentDidMount(){
        // let {data}=await gethome();
        // // console.log(data);
        // this.setState({
        //     list:data
        // })
        this.props.getinit()
    }

    handIeClick=(types)=>{
        this.props.history.push({
            pathname:"/classify",
            query:{
                type:types
            }
        })
    }

    render() { 
        let {list}=this.props
        return (
            <div>
                {
                    list&&list.length?list.map((item,index) => {
                        return <dl key={index} onClick={()=>this.handIeClick(item.type)}>
                            <dt></dt>
                            <dd>{item.name}</dd>
                        </dl>
                    }):<div>暂无数据</div>
                }
            </div>
        );
    }
}
 
export default connect((state)=>{
    return {
        list:state.home
    }
},(dispatch)=>{
    return {
        getinit(){
            dispatch(getHome)
        }
    }
})(Home);